<?php

namespace App\Http\Requests\Project;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class PmProjectUpdateChargerRequest extends FormRequest
{
    /**
     * 表示验证器是否应在第一个规则失败时停止
     *
     * @var bool
     */
    protected $stopOnFirstFailure = true;

    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array|string>
     */
    public function rules(): array
    {
        return [
            'charger' => ['required', 'integer', 'min:1', Rule::exists('App\Models\SysUser', 'id')->whereNull('deleted_at')],
        ];
    }

    /**
     * 获取已定义验证规则的错误消息
     *
     * @return string[]
     */
    public function messages()
    {
        return [
            'charger.required' => '负责人数据不能为空',
            'charger.integer' => '负责人ID必须为整数',
            'charger.exists' => '负责人不存在',
            'charger.min' => '负责人ID必须为一个合法的整数',
        ];
    }
}
